//
//  ViewController.m
//  FootPrint
//
//  Created by alex tao on 2/20/13.
//  Copyright (c) 2013 alex tao. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)dealloc
{
    [_footPrintVC release];
    [_calendarVC release];
    [_friendsVC release];
    [_settingVC release];
    
    [_contentView release];
    [_tabbarView release];
    [_fpBtn release];
    [_calendarBtn release];
    [_friendsBtn release];
    [_settingBtn release];
    [_imgNew release];
    [_fpIcon release];
    [_fpBg release];
    [_calendarBg release];
    [_calendarIcon release];
    [_friendsBg release];
    [_friendsIcon release];
    [_settingBg release];
    [_settingIcon release];
    [super dealloc];
}

- (void)reload
{
    [self showFootPrint:nil];
    
    [_parser inviteRequest:[GConfig getUserId]];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.

    [self showFootPrint:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showNewInvite) name:NOTIFY_INVITE object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(disNewInvite) name:NOTIFY_INVITE_DONE object:nil];
    
    _imgNew.hidden = YES;
    
    _parser = [[FriendParser alloc]init];
    [_parser setInviteDelegate:self];
    [_parser inviteRequest:[GConfig getUserId]];
    
    
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidUnload {
    
    [self setContentView:nil];
    [self setTabbarView:nil];
    [self setFpBtn:nil];
    [self setCalendarBtn:nil];
    [self setFriendsBtn:nil];
    [self setSettingBtn:nil];
    [self setImgNew:nil];
    [self setFpIcon:nil];
    [self setFpBg:nil];
    [self setCalendarBg:nil];
    [self setCalendarIcon:nil];
    [self setFriendsBg:nil];
    [self setFriendsIcon:nil];
    [self setSettingBg:nil];
    [self setSettingIcon:nil];
    [super viewDidUnload];
}


- (void)showNewInvite{
    _imgNew.hidden = NO;
}
- (void)disNewInvite{
     _imgNew.hidden = YES;
}

- (void)didFinishInviteDelegate:(FriendInvitationResponseMessage*)result{
    if(result != nil && [result resultCode]==0){
        if([result invitationList] != nil && [[result invitationList] count]>0){
            [self showNewInvite];
        }
    }
}
- (void)failInvite{

}

- (IBAction)showFootPrint:(id)sender
{
    if(_currentVC != _footPrintVC || nil == _currentVC)
    {
        _fpBtn.selected = YES;
        _fpBg.highlighted = YES;
        _fpIcon.highlighted = YES;
        
        
        _calendarBtn.selected = NO;
        _calendarBg.highlighted = NO;
        _calendarIcon.highlighted = NO;
        
        _friendsBtn.selected = NO;
        _friendsBg.highlighted = NO;
        _friendsIcon.highlighted = NO;
        
        _settingBtn.selected = NO;
        _settingBg.highlighted = NO;
        _settingIcon.highlighted = NO;
        
        
        
        
        if (nil == _footPrintVC){
            _footPrintVC = [[FootPrintViewController alloc] initWithNibName:@"FootPrintViewController" bundle:nil];
            _footPrintVC.view.opaque = NO;
        }
        [_currentVC.view removeFromSuperview];
        _currentVC = _footPrintVC;

        [_contentView addSubview:_footPrintVC.view];
    }
    _footPrintVC.view.frame = CGRectMake(0, 0, _contentView.frame.size.width, _contentView.frame.size.height);
}

- (IBAction)showCanlendar:(id)sender
{
    if(_currentVC != _calendarVC || nil == _currentVC)
    {
        
        _fpBtn.selected = NO;
        _fpBg.highlighted = NO;
        _fpIcon.highlighted = NO;
        
        
        _calendarBtn.selected = YES;
        _calendarBg.highlighted = YES;
        _calendarIcon.highlighted = YES;
        
        _friendsBtn.selected = NO;
        _friendsBg.highlighted = NO;
        _friendsIcon.highlighted = NO;
        
        _settingBtn.selected = NO;
        _settingBg.highlighted = NO;
        _settingIcon.highlighted = NO;
        
        if (nil == _calendarVC){
            _calendarVC = [[CalendarViewController alloc] initWithNibName:@"CalendarViewController" bundle:nil];
            _calendarVC.view.opaque = NO;
        }
        [_currentVC.view removeFromSuperview];
        _currentVC = _calendarVC;
        
        [_contentView addSubview:_calendarVC.view];
        
        [_calendarVC updateCalendarData];
    }
    _calendarVC.view.frame = CGRectMake(0, 0, _contentView.frame.size.width, _contentView.frame.size.height);
}

- (IBAction)showFriends:(id)sender
{
    if(_currentVC != _friendsVC || nil == _currentVC)
    {
        _fpBtn.selected = NO;
        _fpBg.highlighted = NO;
        _fpIcon.highlighted = NO;
        
        
        _calendarBtn.selected = NO;
        _calendarBg.highlighted = NO;
        _calendarIcon.highlighted = NO;
        
        _friendsBtn.selected = YES;
        _friendsBg.highlighted = YES;
        _friendsIcon.highlighted = YES;
        
        _settingBtn.selected = NO;
        _settingBg.highlighted = NO;
        _settingIcon.highlighted = NO;
        
        if (nil == _friendsVC){
            _friendsVC = [[FriendsViewController alloc] initWithNibName:@"FriendsViewController" bundle:nil];
            _friendsVC.view.opaque = NO;
        }
        [_currentVC.view removeFromSuperview];
        _currentVC = _friendsVC;
        
        [_contentView addSubview:_friendsVC.view];
    }
    _friendsVC.view.frame = CGRectMake(0, 0, _contentView.frame.size.width, _contentView.frame.size.height);
}

- (IBAction)showSetting:(id)sender
{
    if(_currentVC != _settingVC || nil == _currentVC)
    {
        _fpBtn.selected = NO;
        _fpBg.highlighted = NO;
        _fpIcon.highlighted = NO;
        
        
        _calendarBtn.selected = NO;
        _calendarBg.highlighted = NO;
        _calendarIcon.highlighted = NO;
        
        _friendsBtn.selected = NO;
        _friendsBg.highlighted = NO;
        _friendsIcon.highlighted = NO;
        
        _settingBtn.selected = YES;
        _settingBg.highlighted = YES;
        _settingIcon.highlighted = YES;
        
        if (nil == _settingVC){
            _settingVC = [[SettingViewController alloc] initWithNibName:@"SettingViewController" bundle:nil];
            _settingVC.view.opaque = NO;
        }
        [_currentVC.view removeFromSuperview];
        _currentVC = _settingVC;
        
        [_contentView addSubview:_settingVC.view];
    }
    _settingVC.view.frame = CGRectMake(0, 0, _contentView.frame.size.width, _contentView.frame.size.height);
}

@end
